// 商铺

function rrr(){
    $('.shop').prop('isExpand', false).click(function () {
        // $('#hit').slideDown(200)
        let isExpand = $('#hit').prop('isExpand')
        if (!isExpand) {
            $('#hit').prop('isExpand', true).slideDown(200)
    
        } else {
            $('#hit').prop('isExpand', false).slideUp(200)
        }
    
    
        $.ajax({
            url: 'http://chst.vip:1234/api/getgsshop',
            success: function (res) {
                console.log(res);
                let data = res.result
                let html = ''
                let hitC = document.querySelector('#hitC')
                data.forEach(item => {
                    html += `
                    <li data-shop="${item.shopId}">
                        ${item.shopName}
                    </li>
                    `
                })
                hitC.innerHTML = html
               
                $('.shop').toggleClass('show');
                hitC.ontouchstart = function (e) {
                    if (e.target.localName === 'li') {
                    
                      
                        
                        let _this = e.target
                        // console.log(_this);
                        let shopid = _this.getAttribute('data-shop')
                        this.setAttribute('shopid',0)
                        this.setAttribute('shopid',shopid)
                       redent()
                    }
                }
            }
        })
    })
    
    
    
    // 地区
    $('.place').prop('isExpand', false).click(function () {
        let isExpand = $('#hit').prop('isExpand')
        if (!isExpand) {
            $('#hit').prop('isExpand', true).slideDown(200)
    
        } else {
            $('#hit').prop('isExpand', false).slideUp(200)
        }
    
        $.ajax({
            url: 'http://chst.vip:1234/api/getgsshoparea',
            success: function (res) {
                console.log(res);
                let data = res.result
                let html = ''
                let hitC = document.querySelector('#hitC')
                data.forEach(item => {
                    html += `
                    <li data-area="${item.areaId}">
                        ${item.areaName}
                    </li>
                    `
                })
                hitC.innerHTML = html
               
                hitC.ontouchstart = function (e) {
                    if (e.target.localName === 'li') {
                        let are = e.target
                        // console.log(are);
                        let areaid = are.getAttribute('data-area')
                        this.setAttribute('areaid',0)
                        this.setAttribute('areaid',areaid)

                    redent()
                    }
                }
            }
        })
    })

}
rrr()

//渲染的内容
// http://chst.vip:1234/api/getgsproduct
function setHtml(shopid = 0, areaid = 0) {
    $.ajax({
        url: 'http://chst.vip:1234/api/getgsproduct',
        data: {
            shopid: shopid,
            areaid: areaid
        },
        success: function (res) {
            console.log(res);
            let data = res.result
            let merchandiseS = document.querySelector('#merchandiseS')
            let html = ''
            data.forEach(item => {
                html += `
                <li>
                <a href="">
                    <img src="${item.productImg}" alt="">
                    <h4>${item.productName}</h4>
                    <p>${item.productPrice}</p>
                </a>
            </li>
                `
            })
            merchandiseS.innerHTML = html
        }
    })
}
setHtml()

function redent(){
    let aa = hitC.getAttribute('areaid')|| 0
    let bb = hitC.getAttribute('shopid') ||0
    setHtml(bb,aa)
}
